package wpmp.auth.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Component;

import wcommons.beanutils.BeanUtils;
import wpmp.utils.quickbean.ButtonConfig;

/**
 * @author Wayne.Wang<5waynewang@gmail.com>
 * @since 3:06:49 PM Dec 26, 2012
 */
@Component
public class ButtonConfigDao extends BaseDao {

	private static final String SQL_GET = "SELECT u_key,disabled,base_url,para_url FROM sys_button_config WHERE u_key=?";

	private static final String SQL_LIST_ALL = "SELECT u_key,disabled,base_url,para_url FROM sys_button_config";

	private static RowMapper<ButtonConfig> DEFAULT_ROW_MAPPER = new RowMapper<ButtonConfig>() {

		@Override
		public ButtonConfig mapRow(ResultSet rs, int rowNum) throws SQLException {
			ButtonConfig dest = new ButtonConfig();
			BeanUtils.copyResultSetToBean(dest, rs);
			dest.setKey(rs.getString("u_key"));
			return dest;
		}
	};

	public ButtonConfig queryForObject(String key) {
		return getJdbcTemplate().queryForObject(SQL_GET, DEFAULT_ROW_MAPPER, key);
	}

	public List<ButtonConfig> queryForList() {
		return getJdbcTemplate().query(SQL_LIST_ALL, DEFAULT_ROW_MAPPER);
	}
}
